import { createVNode, mergeProps, defineComponent, ref, computed, onMounted, resolveDirective, unref, useSSRContext } from "vue";
import { ssrRenderAttrs, ssrGetDirectiveProps, ssrRenderComponent, ssrInterpolate, ssrRenderStyle } from "vue/server-renderer";
import { C as CustomerServiceIcon } from "./CustomerServiceIcon-20eb4cc1.js";
import { I as IconWrapper, l as useNativeInfoStore, G as getCookie, J as getCustomerServiceInfo, p as useMainStore, K as getLocalStore, L as useMountedHook, O as OrderIcon, N as getUnreadMsgCountApi, _ as _export_sfc } from "../entry-server.js";
import "qs";
import { sha256 } from "js-sha256";
import { useI18n } from "vue-i18n";
import { useEventListener } from "@vueuse/core";
import { useRouter, useRoute } from "vue-router";
const FacebookIcon = IconWrapper((props) => createVNode("svg", mergeProps(props, {
  "class": {
    "svg-color-fill": Boolean(props.fill)
  },
  "style": {
    "--fill-color": props.fill
  },
  "xmlns": "http://www.w3.org/2000/svg",
  "fill": "none",
  "viewBox": "0 0 28 28"
}), [createVNode("path", {
  "fill": "#444",
  "d": "M18 6.123V8.82h-1.635c-.598 0-1 .122-1.209.367-.208.246-.312.614-.312 1.104v1.93h3.052l-.406 3.025h-2.646V23h-3.188v-7.754H9v-3.024h2.656V9.995c0-1.267.361-2.25 1.084-2.948C13.462 6.35 14.424 6 15.625 6c1.02 0 1.813.04 2.375.123Z",
  "clip-rule": "evenodd",
  "fill-rule": "evenodd",
  "data-follow-fill": "#444"
}, null)]));
function randomString() {
  const numberLetters = Array.from({ length: 10 }).map((_, idx) => String.fromCharCode(idx + "0".charCodeAt(0)));
  const lowerCaseLetters = Array.from({ length: 26 }).map((_, idx) => String.fromCharCode(idx + "a".charCodeAt(0)));
  const pool = numberLetters.concat(lowerCaseLetters);
  let res = "";
  for (let i = 0; i < 30; i++) {
    const id = Math.floor(Math.random() * 36);
    res += pool[id];
  }
  return res;
}
function generateParams() {
  const nativeInfoStore = useNativeInfoStore();
  const appInfo = nativeInfoStore.getNativeInfo();
  const mainStore = useMainStore();
  const country = mainStore.getCurrentCountryName;
  const lang = window.PatPat ? appInfo.language : mainStore.language;
  const site = appInfo.siteAbb || mainStore.siteAbb;
  const nonce = randomString();
  const timestamp = (/* @__PURE__ */ new Date()).getTime();
  const platform = appInfo.isAndroid ? "Andoroid" : appInfo.isIos ? "ios" : "wap";
  const appUserInfo = {
    email: appInfo.email,
    user_id: appInfo.userId,
    gender: "",
    first_name: "",
    last_name: "",
    is_new_user: ""
  };
  const userInfo = window.PatPat ? appUserInfo : getLocalStore("userInfo");
  let signStr = "nonce=" + nonce + "&timestamp=" + timestamp + "&web_token=" + userInfo.user_id + "&b5229fb58d0001a1844114d33f714500";
  signStr = sha256(signStr).toUpperCase();
  return `&c_cf_country=${country}&c_cf_platform=${platform}&c_cf_language=${lang}&c_cf_site=${site}&c_email=${encodeURIComponent(
    userInfo.email
  )}&c_cf_userId=${userInfo.user_id}&c_cf_gender=${encodeURIComponent(userInfo.gender)}&c_cf_first_name=${encodeURIComponent(
    userInfo.first_name
  )}&c_cf_last_name=${encodeURIComponent(userInfo.last_name)}&c_cf_new_user=${encodeURIComponent(
    userInfo.is_new_user
  )}&nonce=${nonce}&timestamp=${timestamp}&web_token=${userInfo.user_id}&b5229fb58d0001a1844114d33f714500&encryption_algorithm=SHA256&signature=${signStr}`;
}
function udeskSDK(data) {
  if (!document.getElementById("udesk-sdk")) {
    let initial2 = function() {
      var _a;
      window.UdeskApiObject = "ud";
      function defaultUDFn(...args) {
        window["ud"].d = window["ud"].d || [];
        window["ud"].d.push(args);
      }
      window["ud"] = window["ud"] || defaultUDFn;
      const script = document.createElement("script");
      script.id = "udesk-sdk";
      script.async = true;
      script.setAttribute("chartset", "utf-8");
      script.src = "https://assets-cli.s5.udesk.cn/im_client/js/udeskApi.js";
      const firstScript = document.getElementsByTagName("script")[0];
      (_a = firstScript.parentElement) == null ? void 0 : _a.insertBefore(script, firstScript);
    };
    initial2();
  }
  udeskService(data);
}
function udeskService(data) {
  const groupId = data.group_id;
  const webPluginId = data.web_plugin_id;
  const language = data.language;
  const link = `https://1912059.s5.udesk.cn/im_client/?web_plugin_id=${webPluginId}&group_id=${groupId}&language=${language}${generateParams()}`;
  window.ud({
    code: "2id00j",
    link,
    targetSelector: "#customer-service"
  });
}
function detectLoginStatus(force) {
  const nativeInfoStore = useNativeInfoStore();
  const appInfo = nativeInfoStore.getNativeInfo();
  const loginStatus = appInfo.isLogin || getCookie("loginStatus") === "true";
  console.log("loginStatus", loginStatus);
  if (loginStatus || force) {
    getCustomerServiceInfo().then((data) => udeskSDK(data)).catch(() => {
    });
  } else {
    window.location.href = "/account/login";
  }
}
const WhatsappIcon = IconWrapper((props) => createVNode("svg", mergeProps(props, {
  "class": {
    "svg-color-fill": Boolean(props.fill)
  },
  "style": {
    "--fill-color": props.fill
  },
  "xmlns": "http://www.w3.org/2000/svg",
  "fill": "none",
  "viewBox": "0 0 28 28"
}), [createVNode("path", {
  "fill": "#444",
  "d": "M11.71 10.397c-.153-.364-.27-.378-.5-.388a4.565 4.565 0 0 0-.265-.009c-.3 0-.616.088-.806.282-.23.235-.806.785-.806 1.913 0 1.128.825 2.218.936 2.371.116.152 1.608 2.5 3.923 3.457 1.811.748 2.349.68 2.761.591.602-.13 1.357-.573 1.547-1.109.19-.536.19-.994.135-1.091-.056-.097-.209-.152-.44-.268-.232-.115-1.358-.67-1.571-.744-.209-.078-.407-.05-.565.171-.222.31-.44.624-.616.814-.139.148-.366.166-.556.088-.254-.107-.968-.356-1.848-1.138-.681-.605-1.144-1.358-1.278-1.584-.135-.232-.014-.366.092-.49.116-.144.227-.245.343-.379.116-.134.18-.203.255-.36.078-.153.023-.31-.033-.426-.055-.115-.519-1.243-.709-1.7ZM13.997 6h.004C18.413 6 22 9.589 22 14s-3.587 8-7.998 8a7.936 7.936 0 0 1-4.4-1.321l-3.075.982.996-2.972A7.942 7.942 0 0 1 6 14c0-4.411 3.587-8 7.998-8Z",
  "clip-rule": "evenodd",
  "fill-rule": "evenodd",
  "data-follow-fill": "#444"
}, null)]));
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "HelpCenterFooter",
  __ssrInlineRender: true,
  props: {
    ticketRecord: { type: Boolean, default: false }
  },
  setup(__props) {
    const props = __props;
    const { t } = useI18n();
    const helpCenterFooterRef = ref();
    useNativeInfoStore();
    const mainStore = useMainStore();
    useRouter();
    const langCode = computed(() => mainStore.language);
    const route = useRoute();
    const trackPageName = computed(() => {
      var _a;
      const name = ((_a = route.meta) == null ? void 0 : _a.trackPageName) || "";
      return name ? name + "_" : "";
    });
    const showUnreadMsgDot = ref(false);
    const isARSite = computed(() => {
      return mainStore.siteAbb === "ar";
    });
    function updateUnreadMsgCount() {
      if (props.ticketRecord) {
        getUnreadMsgCountApi().then((data) => {
          showUnreadMsgDot.value = data.replay_not_read_count !== 0;
        });
      }
    }
    useMountedHook(() => {
      updateUnreadMsgCount();
    });
    onMounted(() => {
      detectLoginStatus(true);
      useEventListener(window, "appLogin", (event) => {
        event.detail && detectLoginStatus();
      });
    });
    return (_ctx, _push, _parent, _attrs) => {
      const _directive_track = resolveDirective("track");
      _push(`<div${ssrRenderAttrs(mergeProps({
        ref_key: "helpCenterFooterRef",
        ref: helpCenterFooterRef,
        class: "hc-footer"
      }, _attrs))} data-v-ad82e3b0><button${ssrRenderAttrs(mergeProps({
        id: "customer-service",
        class: "footer-item"
      }, ssrGetDirectiveProps(_ctx, _directive_track, { pId: trackPageName.value + "livechat_button", eventName: "livechat_button" }, void 0, {
        click: true,
        exposure: true
      })))} data-v-ad82e3b0><div class="footer-icon" data-v-ad82e3b0>`);
      _push(ssrRenderComponent(unref(CustomerServiceIcon), {
        width: 28,
        height: 28,
        name: "customer-service"
      }, null, _parent));
      _push(`</div><div class="footer-txt" data-v-ad82e3b0><span data-v-ad82e3b0>${ssrInterpolate(unref(t)("helpCenter.liveChat"))}</span><span style="${ssrRenderStyle({ "color": "#b3b3b3" })}" data-v-ad82e3b0>${ssrInterpolate(unref(t)("helpCenter.24h_online"))}</span></div></button><button${ssrRenderAttrs(mergeProps({ class: "footer-item" }, ssrGetDirectiveProps(_ctx, _directive_track, { pId: trackPageName.value + "ticket_button", eventName: "ticket_button" }, void 0, {
        click: true,
        exposure: true
      })))} data-v-ad82e3b0><div class="footer-icon" data-v-ad82e3b0>`);
      if (showUnreadMsgDot.value) {
        _push(`<i class="red-dot" data-v-ad82e3b0></i>`);
      } else {
        _push(`<!---->`);
      }
      _push(ssrRenderComponent(unref(OrderIcon), {
        width: 28,
        height: 28,
        name: "order"
      }, null, _parent));
      _push(`</div>`);
      if (langCode.value === "de") {
        _push(`<div class="footer-txt" data-v-ad82e3b0><span data-v-ad82e3b0>Ticket einreichen und aufzeichnen</span></div>`);
      } else {
        _push(`<div class="footer-txt" data-v-ad82e3b0><span data-v-ad82e3b0>${ssrInterpolate(unref(t)("helpCenter.ticket"))}</span><span data-v-ad82e3b0>${ssrInterpolate(props.ticketRecord ? unref(t)("helpCenter.submit_record") : unref(t)("helpCenter.submit"))}</span></div>`);
      }
      _push(`</button>`);
      if (isARSite.value) {
        _push(`<button${ssrRenderAttrs(mergeProps({ class: "footer-item" }, ssrGetDirectiveProps(_ctx, _directive_track, { pId: trackPageName.value + "whatsapp_button", eventName: "whatsapp_button" }, void 0, {
          click: true,
          exposure: true
        })))} data-v-ad82e3b0><div class="footer-icon" data-v-ad82e3b0>`);
        _push(ssrRenderComponent(unref(WhatsappIcon), {
          width: 28,
          height: 28,
          name: "Whatsapp"
        }, null, _parent));
        _push(`</div><div class="footer-txt" data-v-ad82e3b0><span data-v-ad82e3b0>Whatsapp</span></div></button>`);
      } else {
        _push(`<button${ssrRenderAttrs(mergeProps({ class: "footer-item" }, ssrGetDirectiveProps(_ctx, _directive_track, { pId: trackPageName.value + "facebook_button", eventName: "facebook_button" }, void 0, {
          click: true,
          exposure: true
        })))} data-v-ad82e3b0><div class="footer-icon" data-v-ad82e3b0>`);
        _push(ssrRenderComponent(unref(FacebookIcon), {
          width: 28,
          height: 28,
          name: "facebook"
        }, null, _parent));
        _push(`</div><div class="footer-txt" data-v-ad82e3b0><span data-v-ad82e3b0>Facebook</span><span data-v-ad82e3b0>messenger</span></div></button>`);
      }
      _push(`</div>`);
    };
  }
});
const HelpCenterFooter_vue_vue_type_style_index_0_scoped_ad82e3b0_lang = "";
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
  const ssrContext = useSSRContext();
  (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("src/views/helpCenter/components/HelpCenterFooter.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const HelpCenterFooter = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-ad82e3b0"]]);
export {
  HelpCenterFooter as H
};
